package com.qffx.moviebase.utils.common;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.qffx.moviebase.R;

/**
 * Created by lx on 2017/2/9.
 */

public class FindRecyclerView extends PullToRefreshBase<RecyclerView> {
    public int sroll = 0;

    public FindRecyclerView(Context context) {
        super(context);
    }

    public FindRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    //垂直方向
    @Override
    public Orientation getPullToRefreshScrollDirection() {
        return Orientation.VERTICAL;
    }

    @Override
    protected RecyclerView createRefreshableView(Context context, AttributeSet attrs) {
        RecyclerView recyclerView = new RecyclerView(context);
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setId(R.id.find_recyclervie);
        return recyclerView;
    }

    @Override
    protected boolean isReadyForPullEnd() {
        View view = getRefreshableView().getChildAt(getRefreshableView().getChildCount() - 1);
        if (null != view) {
            if (getRefreshableView().getBottom() >= view.getBottom()) {
                sroll = getRefreshableView().getBottom() - view.getBottom();
                return true;
            } else
                return false;

        }
        return false;
    }

    @Override
    protected boolean isReadyForPullStart() {
        View view = getRefreshableView().getChildAt(0);
        if (view != null) {
            return view.getTop() >= getRefreshableView().getTop();
        }
        return false;
    }
}